package com.xrit.sunnyday.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.service.SetmealService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 任务调度类
 */
@Component("cleanImgJob")
public class CleanImgJob {
    /**
     * 订阅服务
     */
    @Reference
    private SetmealService setmealService;

    public void cleanImg(){
        // 查出7牛上的所有图片
        List<String> imgIn7Niu = QiNiuUtils.listFile();
        // 查出数据库中的所有图片
        List<String> imgInDb = setmealService.findImgs();
        imgIn7Niu.removeAll(imgInDb);
        String[] strings = imgIn7Niu.toArray(new String[]{});
        QiNiuUtils.removeFiles(strings);
    }
}
